package com.wf.day_0607.test1;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Scanner;

/**
 * @author mpk
 * @since 2024/6/7 17:33:37
 */
public class UserTest {
    public static void main(String[] args) throws IOException {


        try (InputStream inputStream = UserTest.class.getResourceAsStream("user.txt");
             BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));) {


            ArrayList<User> users = new ArrayList<>();
            String u;
            while ((u = reader.readLine()) != null) {
                String[] us = u.split("#");

                User user = new User(us[0], us[1]);
                users.add(user);
            }

            Scanner scanner = new Scanner(System.in);

            System.out.println("请输入用户名：");
            String name = scanner.nextLine();
            System.out.println("请输入密码：");
            String password = scanner.nextLine();

            User user = new User(name, password);

            if (users.contains(user)) {
                System.out.println("登陆成功！");
            } else {
                System.err.println("登录失败！");
            }

        }


    }


}
